import tkinter as tk
from tkinter import messagebox

def sort_ascending():
    input1 = entry.get()
    try:
        # 将输入的字符串分割为数字列表
        numbers = [int(num) for num in input1.split()]
        # 从小到大排序
        numbers.sort(reverse=False)
        result_text = " ".join(str(num) for num in numbers)
        output_label.config(text=result_text)
    except ValueError:
        messagebox.showerror("错误", "请输入有效的数字，用空格分隔")

def sort_descending():
    input1 = entry.get()
    try:
        # 将输入的字符串分割为数字列表
        numbers = [int(num) for num in input1.split()]
        # 从大到小排序
        numbers.sort(reverse=True)
        result_text = " ".join(str(num) for num in numbers)
        output_label.config(text=result_text)
    except ValueError:
        messagebox.showerror("错误", "请输入有效的数字，用空格分隔")

# 创建主窗口
root = tk.Tk()
root.title("数字排序")
root.geometry("600x300")

# 输入框
entry_label = tk.Label(root, text="请输入数字，用空格分隔:")
entry_label.pack(pady=10)
entry = tk.Entry(root)
entry.pack(pady=10)

# 从小到大排序按钮
button1 = tk.Button(root, text="从小到大排序", command=sort_ascending)
button1.pack(pady=10)

# 从大到小排序按钮
button2 = tk.Button(root, text="从大到小排序", command=sort_descending)
button2.pack(pady=10)

# 输出标签
output_label = tk.Label(root, text="")
output_label.pack(pady=10)

# 运行主界面
root.mainloop()